package com.woniuxy.depot.controller;

import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.woniuxy.depot.model.DTO.StockGoodsDTO;
import com.woniuxy.depot.model.VO.PageBean;
import com.woniuxy.depot.model.VO.StockGoodsVO;
import com.woniuxy.depot.service.DepotStockManageService;
import com.woniuxy.model.entity.Goods;
import com.woniuxy.model.vo.DepotStockManageVo;
import com.woniuxy.response.R;
import com.woniuxy.response.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/stockManage")
public class DepotStockManageController {
    @Resource
    private DepotStockManageService stockManageService;
    @PostMapping("/searchByCondition")
    public ResponseResult<PageBean<StockGoodsVO>> searchByCondition(@RequestBody StockGoodsDTO stockGoodsDTO){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",stockManageService.searchByCondition(stockGoodsDTO));
    }

    @PostMapping("/delStock")
    public ResponseResult<Boolean> delStock(@RequestBody DepotStockManageVo stockManageVo){
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",stockManageService.delStock(stockManageVo));
    }

    @PostMapping("/generateExcel")
    public ResponseResult<Boolean> generateExcel(@RequestBody List<Goods> list) {
        //通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("C:/Users/chenlin/Desktop/table/仓库管理单.xlsx");
        //跳过当前行，既第一行，非必须，在此演示用
        //writer.passCurrentRow();
        //合并单元格后的标题行，使用默认标题样式
        writer.merge(list.size(), "仓库管理单");
        //一次性写出内容，强制输出标题
        writer.write(list, true);
        //关闭writer，释放内存
        writer.close();
        return new ResponseResult<>(ResponseResult.SUCCESS,"success",stockManageService.insertExcel());
    }

}
